//2019240016 大数据191 刘艺 实验一 进程管理
#include<windows.h>
#include<process.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>

struct  PROCESS{
    intptr_t hProcess;
    char name[40];
} process[4] = {{0,"Anny"},{0, "Beth"},
                {0,"Carl"},{0,"Dave"}};

int main(int argc, char* argv[]){
    int termstat, c;
    //char Name[4] ={"平平","安安","团团","圆圆"};

    srand((unsigned ) time(NULL));  //清空键盘输入缓冲区

    //调用过程
    if(argc == 1){
        for (int c = 0; c < 4; c++) {
            _flushall();
            process[c].hProcess = _spawnl(_P_NOWAIT, argv[0], argv[0],
                                          process[c].name,NULL);
        }

        c = rand() % 4;
        printf("Come here, %s. \n",process[c].name);
        _cwait(&termstat, process[c].hProcess, _WAIT_CHILD);
        printf("Thank you, %s.\n", process[c].name);

        getchar();
    }
    else{
        Sleep((argv[1][0] - 'A' + 1) * 1000l);
        printf("Hi, Dad. It's %s.\n",argv[1]);
    }

}

